package yazan.com.pdacollector_android.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import yazan.com.pdacollector_android.R;
import yazan.com.pdacollector_android.model.Goods;
import yazan.com.pdacollector_android.utils.PDAGlobal;

public class OrderDetailAdapter extends BaseQuickAdapter<Goods, BaseViewHolder> {

    private Context context;

    public OrderDetailAdapter(int layoutResId, @Nullable List<Goods> data, Context context) {
        super(layoutResId, data);
        this.context = context;
    }


    @Override
    protected void convert(BaseViewHolder helper, Goods item) {
        if (helper.getAdapterPosition() == PDAGlobal.selectPosition) {
            helper.itemView.setBackgroundColor(context.getResources().getColor(R.color.colorRed));
        } else {
            if (item.getValidation_type() == 1) {
                helper.itemView.setBackgroundColor(context.getResources().getColor(R.color.darkgray));
            } else {
                helper.itemView.setBackgroundColor(context.getResources().getColor(R.color.colorWhite));
            }
        }

        helper.setText(R.id.tvIndex, item.getFIndex() + "");
        helper.setText(R.id.tvGoodName, item.getFgoods_name());
        helper.setText(R.id.tvBarcode, item.getFgoods_sn());
        helper.setText(R.id.tvSpecification, item.getFgoods_spec());
        helper.setText(R.id.tvCount, item.getFgoods_qty() + "");
        helper.setText(R.id.tvValidationCount, item.getFgoods_qty() + "/" + item.getValidation_count());
        if (item.getFiscode() == 1) {
            helper.getView(R.id.tvTrace).setVisibility(View.VISIBLE);
        } else {
            helper.getView(R.id.tvTrace).setVisibility(View.GONE);
        }
    }
}
